
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>环境配置 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-codeblock-label/block.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-click-reveal/click_reveal.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="testing.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    实验简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../log.html">
            
                <a href="../log.html">
            
                    
                    更新日志
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">零：前置准备</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    配环境、跑测试
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="2.1.1" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="testing.html">
            
                <a href="testing.html">
            
                    
                    运行测试样例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="riscv.html">
            
                <a href="riscv.html">
            
                    
                    RISC-V 的工具链使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">第一个编译器</li>
        
        
    
        <li class="chapter " data-level="3.1" >
            
                <span>
            
                    
                    step1：仅一个 return 的 main 函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../lab1/part1.html">
            
                <a href="../lab1/part1.html">
            
                    
                    从零开始的 lexer、parser 以及汇编生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../lab1/part2.html">
            
                <a href="../lab1/part2.html">
            
                    
                    词法语法分析工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../lab1/part3.html">
            
                <a href="../lab1/part3.html">
            
                    
                    使用中间码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.4.1" data-path="../lab1/antlr.html">
            
                <a href="../lab1/antlr.html">
            
                    
                    ANTLR 使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.2" data-path="../lab1/visitor.html">
            
                <a href="../lab1/visitor.html">
            
                    
                    Visitor 模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4.3" data-path="../lab1/ir.html">
            
                <a href="../lab1/ir.html">
            
                    
                    IR 简明介绍
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../lab1/spec.html">
            
                <a href="../lab1/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">常量表达式</li>
        
        
    
        <li class="chapter " data-level="4.1" >
            
                <span>
            
                    
                    step2：一元操作
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../lab2/intro.html">
            
                <a href="../lab2/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../lab2/guide.html">
            
                <a href="../lab2/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../lab2/spec.html">
            
                <a href="../lab2/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" >
            
                <span>
            
                    
                    step3：加减乘除模
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="../lab3/intro.html">
            
                <a href="../lab3/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="../lab3/guide.html">
            
                <a href="../lab3/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2.3" data-path="../lab3/spec.html">
            
                <a href="../lab3/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" >
            
                <span>
            
                    
                    step4：比较和逻辑表达式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="../lab4/intro.html">
            
                <a href="../lab4/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.2" data-path="../lab4/guide.html">
            
                <a href="../lab4/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="../lab4/spec.html">
            
                <a href="../lab4/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">变量和语句</li>
        
        
    
        <li class="chapter " data-level="5.1" >
            
                <span>
            
                    
                    step5：局部变量和赋值
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../lab5/intro.html">
            
                <a href="../lab5/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../lab5/guide.html">
            
                <a href="../lab5/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.3" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.3.1" data-path="../lab5/stackframe.html">
            
                <a href="../lab5/stackframe.html">
            
                    
                    栈帧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.1.4" data-path="../lab5/spec.html">
            
                <a href="../lab5/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.2" >
            
                <span>
            
                    
                    step6：if 语句和条件表达式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.2.1" data-path="../lab6/intro.html">
            
                <a href="../lab6/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2.2" data-path="../lab6/guide.html">
            
                <a href="../lab6/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2.3" data-path="../lab6/spec.html">
            
                <a href="../lab6/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">块语句和作用域和更多语句</li>
        
        
    
        <li class="chapter " data-level="6.1" >
            
                <span>
            
                    
                    step7：作用域和块语句
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1.1" data-path="../lab7/intro.html">
            
                <a href="../lab7/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.2" data-path="../lab7/guide.html">
            
                <a href="../lab7/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.1.3" data-path="../lab7/spec.html">
            
                <a href="../lab7/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6.2" >
            
                <span>
            
                    
                    step8：循环语句
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.2.1" data-path="../lab8/intro.html">
            
                <a href="../lab8/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2.2" data-path="../lab8/guide.html">
            
                <a href="../lab8/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2.3" data-path="../lab8/spec.html">
            
                <a href="../lab8/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">函数和全局变量</li>
        
        
    
        <li class="chapter " data-level="7.1" >
            
                <span>
            
                    
                    step9：函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="../lab9/intro.html">
            
                <a href="../lab9/intro.html">
            
                    
                    任务概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="../lab9/guide.html">
            
                <a href="../lab9/guide.html">
            
                    
                    实验指导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.1.3" >
            
                <span>
            
                    
                    其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.3.1" data-path="../lab9/calling.html">
            
                <a href="../lab9/calling.html">
            
                    
                    函数调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.1.4" data-path="../lab9/spec.html">
            
                <a href="../lab9/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" >
            
                <span>
            
                    
                    step10：全局变量
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.2.1" data-path="../lab10/part0-intro.html">
            
                <a href="../lab10/part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.2" data-path="../lab10/part1-parser.html">
            
                <a href="../lab10/part1-parser.html">
            
                    
                    词法语法分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.3" data-path="../lab10/part1-1-task.html">
            
                <a href="../lab10/part1-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.4" data-path="../lab10/part4-codegen.html">
            
                <a href="../lab10/part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.5" data-path="../lab10/part4-1-task.html">
            
                <a href="../lab10/part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.6" data-path="../lab10/summary.html">
            
                <a href="../lab10/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2.7" data-path="../lab10/spec.html">
            
                <a href="../lab10/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">指针和数组</li>
        
        
    
        <li class="chapter " data-level="8.1" >
            
                <span>
            
                    
                    step11：指针
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1.1" data-path="../lab11/part0-intro.html">
            
                <a href="../lab11/part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.2" data-path="../lab11/typeck.html">
            
                <a href="../lab11/typeck.html">
            
                    
                    类型检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.3" data-path="../lab11/part4-codegen.html">
            
                <a href="../lab11/part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.4" data-path="../lab11/part4-1-task.html">
            
                <a href="../lab11/part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.5" data-path="../lab11/summary.html">
            
                <a href="../lab11/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.1.6" data-path="../lab11/spec.html">
            
                <a href="../lab11/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8.2" >
            
                <span>
            
                    
                    step12：数组
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.2.1" data-path="../lab12/part0-intro.html">
            
                <a href="../lab12/part0-intro.html">
            
                    
                    摘要
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.2" data-path="../lab12/part4-codegen.html">
            
                <a href="../lab12/part4-codegen.html">
            
                    
                    代码生成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.3" data-path="../lab12/part4-1-task.html">
            
                <a href="../lab12/part4-1-task.html">
            
                    
                    任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.4" data-path="../lab12/summary.html">
            
                <a href="../lab12/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2.5" data-path="../lab12/spec.html">
            
                <a href="../lab12/spec.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">参考资料</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../../REFERENCE.html">
            
                <a href="../../REFERENCE.html">
            
                    
                    参考资料
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >环境配置</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x73AF;&#x5883;&#x914D;&#x7F6E;">&#x73AF;&#x5883;&#x914D;&#x7F6E;</h1>
<h2 id="&#x5FC5;&#x505A;&#xFF1A;risc-v-&#x7684;-gcc-&#x548C;-qemu">&#x5FC5;&#x505A;&#xFF1A;RISC-V &#x7684; gcc &#x548C; qemu</h2>
<p>&#x6211;&#x4EEC;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#x53EA;&#x751F;&#x6210; RISC-V &#x6C47;&#x7F16;&#xFF0C;&#x4F46;&#x662F;&#x63D0;&#x4F9B;&#x9884;&#x7F16;&#x8BD1;&#x7684; gcc &#x548C; qemu &#x6A21;&#x62DF;&#x5668;&#x3002;
gcc &#x7528;&#x6765;&#x628A; C &#x7F16;&#x8BD1;&#x5230;&#x6C47;&#x7F16;&#x3001;&#x4EE5;&#x53CA;&#x628A;&#x6C47;&#x7F16;&#x53D8;&#x6210; RISC-V &#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#xFF1B;qemu &#x7528;&#x6765;&#x8FD0;&#x884C; RISC-V &#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x3002;
&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x7684; gcc &#x548C; qemu &#x53EA;&#x80FD;&#x5728; Linux/Mac &#x4E0B;&#x8FD0;&#x884C;&#xFF0C;<strong>Windows &#x7684;&#x540C;&#x5B66;</strong> &#x53EF;&#x4EE5;&#x4F7F;&#x7528; WSL&#xFF0C;&#x6216;&#x8005;&#x8FD0;&#x884C;&#x4E00;&#x4E2A;&#x865A;&#x62DF;&#x673A;&#x3002;
&#x5173;&#x4E8E; WSL / &#x865A;&#x62DF;&#x673A;&#x4F7F;&#x7528;&#xFF0C;&#x4EE5;&#x53CA; Linux &#x57FA;&#x7840;&#x64CD;&#x4F5C;&#xFF0C;&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x81EA;&#x5DF1;&#x5728;&#x7F51;&#x4E0A;&#x67E5;&#x627E;&#x8D44;&#x6599;&#x3002;</p>
<pre><code>                  &#x4F60;&#x7684;&#x7F16;&#x8BD1;&#x5668;                gcc               qemu
MiniDecaf &#x6E90;&#x6587;&#x4EF6; ------------&gt; RISC-V &#x6C47;&#x7F16; -----&gt; &#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6; --------&gt; &#x8F93;&#x51FA;
</code></pre><p>&#x8FD9;&#x4E00;&#x6B65;&#x7684;&#x73AF;&#x5883;&#x914D;&#x7F6E;&#x6307;&#x5357;</p>
<h3 id="windows-&#x7528;&#x6237;">Windows &#x7528;&#x6237;</h3>
<p>&#x6682;&#x4E0D;&#x652F;&#x6301; Windows&#xFF0C;&#x8BF7;&#x81EA;&#x884C;&#x914D;&#x7F6E;&#x597D; WSL / &#x865A;&#x62DF;&#x673A;&#x3002;</p>
<h3 id="linux-&#x7528;&#x6237;">Linux &#x7528;&#x6237;</h3>
<ol>
<li><p>&#x4ECE;&#x7F51;&#x7EDC;&#x5B66;&#x5802;&#x4E0B;&#x8F7D; riscv-prebuilt.tar.gz &#x538B;&#x7F29;&#x5305;&#x5E76;&#x89E3;&#x538B;&#xFF08;&#x547D;&#x4EE4;&#x662F; <code>tar xzf riscv-prebuilt.tar.gz</code>&#xFF09;</p>
</li>
<li><p>&#x5B89;&#x88C5;&#x5DE5;&#x5177;&#x94FE; <code>cp riscv-prebuilt/* /usr/ -r</code></p>
</li>
</ol>
<blockquote>
<p>&#x5728;&#x7B2C; 2. &#x6B65;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x9009;&#x62E9;&#x4E0D;&#x5B89;&#x88C5;&#x5230;&#x7CFB;&#x7EDF;&#x76EE;&#x5F55;&#x4E0B;&#x3002;&#x76F8;&#x5E94;&#x7684;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF1A;
<code>export PATH=$PATH:/path/to/riscv-prebuilt/bin</code>&#xFF0C;&#x628A; <code>/path/to</code> &#x66FF;&#x6362;&#x4E3A;&#x4F60;&#x7684;&#x89E3;&#x538B;&#x76EE;&#x5F55;</p>
</blockquote>
<p>&#x6267;&#x884C;&#x4E0B;&#x9762;&#x547D;&#x4EE4;&#x6D4B;&#x8BD5;&#x4F60; gcc &#x548C; qemu &#x662F;&#x5426;&#x6210;&#x529F;&#x5B89;&#x88C5; <sup><a href="#fn_1" id="reffn_1">1</a></sup>&#xFF1A;</p>
<ol>
<li><p>&#x521B;&#x5EFA; <code>test.c</code> &#x6587;&#x4EF6;&#xFF0C;&#x5176;&#x4E2D;&#x5199;&#x5165;&#x5982;&#x4E0B;&#x5185;&#x5BB9;</p>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdio.h&gt;</span></span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{ <span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;Hello world!\n&quot;</span>); }
</code></pre>
</li>
<li><p>&#x7F16;&#x8BD1; <code>test.c</code> &#x6587;&#x4EF6;&#xFF0C;<code>gcc</code> &#x5E94;&#x8BE5;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6; <code>a.out</code>&#x3002;&#x4F46; <code>a.out</code> &#x662F; RISC-V &#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x7684; X86 &#x8BA1;&#x7B97;&#x673A;&#x65E0;&#x6CD5;&#x8FD0;&#x884C;&#x3002;</p>
<pre><code class="lang-bash">$ riscv64-unknown-elf-gcc -march=rv32im -mabi=ilp32 -O3 -S test.c
$ ls a.out
a.out
$ ./a.out
bash: ./a.out: cannot execute binary file: Exec format error
</code></pre>
</li>
<li><p>&#x4F7F;&#x7528; qemu &#x6267;&#x884C; <code>a.out</code></p>
<pre><code class="lang-bash">$ qemu-riscv32 a.out
Hello world!
</code></pre>
</li>
</ol>
<h3 id="macos-&#x7528;&#x6237;">macOS &#x7528;&#x6237;</h3>
<ol>
<li>&#x4ECE;<a href="https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.0-x86_64-apple-darwin.tar.gz" target="_blank">&#x8FD9;&#x91CC;</a>&#x4E0B;&#x8F7D;&#x9884;&#x7F16;&#x8BD1;&#x597D;&#x7684; RISC-V &#x5DE5;&#x5177;&#x94FE;&#x5E76;&#x89E3;&#x538B;&#x3002;</li>
<li><p>&#x7531;&#x4E8E; macOS &#x4E0D;&#x652F;&#x6301; QEMU &#x7684;&#x7528;&#x6237;&#x6001;&#x6A21;&#x5F0F;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528; <a href="https://github.com/riscv/riscv-isa-sim" target="_blank">Spike</a> &#x6A21;&#x62DF;&#x5668;&#x548C;&#x4E00;&#x4E2A;&#x7B80;&#x6613;&#x5185;&#x6838; <a href="https://github.com/riscv/riscv-pk" target="_blank">riscv-pk</a> &#x63D0;&#x4F9B;&#x7528;&#x6237;&#x6001;&#x7A0B;&#x5E8F;&#x7684;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x3002;&#x7F51;&#x7EDC;&#x5B66;&#x5802;&#x4E0A;&#x63D0;&#x4F9B;&#x4E86;&#x6211;&#x4EEC;&#x9884;&#x7F16;&#x8BD1;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x7A0B;&#x5E8F;&#x5305; spike-pk-prebuilt-x86_64-apple-darwin.tar.gz&#x3002;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <a href="https://brew.sh/" target="_blank">Homebrew</a> &#x5B89;&#x88C5; Spike <sup><a href="#fn_2" id="reffn_2">2</a></sup>&#xFF1A;</p>
<pre><code class="lang-bash">$ brew tap riscv/riscv
$ brew install riscv-isa-sim
</code></pre>
</li>
<li><p>&#xFF08;&#x53EF;&#x9009;&#xFF09;&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF0C;&#x4EE5;&#x4FBF;&#x6BCF;&#x6B21;&#x4F7F;&#x7528;&#x65F6;&#x4E0D;&#x9700;&#x8981;&#x8F93;&#x5165;&#x5B8C;&#x6574;&#x8DEF;&#x5F84;&#x3002;</p>
</li>
<li>&#x6D4B;&#x8BD5;&#x4F60; GCC &#x548C; Spike &#x662F;&#x5426;&#x6210;&#x529F;&#x5B89;&#x88C5;&#xFF0C;&#x8BE6;&#x89C1;<a href="riscv.html">RISC-V &#x7684;&#x5DE5;&#x5177;&#x94FE;&#x4F7F;&#x7528;</a>&#x3002;</li>
</ol>
<h2 id="&#x63A8;&#x8350;&#xFF1A;&#x53C2;&#x8003;&#x5B9E;&#x73B0;&#x7684;&#x73AF;&#x5883;">&#x63A8;&#x8350;&#xFF1A;&#x53C2;&#x8003;&#x5B9E;&#x73B0;&#x7684;&#x73AF;&#x5883;</h2>
<p>&#x6211;&#x4EEC;&#x5F3A;&#x70C8;&#x63A8;&#x8350;&#x4F60;&#x9009;&#x62E9;&#x4E00;&#x4E2A;&#x53C2;&#x8003;&#x5B9E;&#x73B0;&#xFF0C;&#x5E76;&#x4E14;&#x5148;&#x6D4B;&#x8BD5;&#x8FD0;&#x884C;&#xFF08;&#x89C1;&#x4E0B;&#x4E00;&#x8282;&#xFF09;&#x4E00;&#x4E0B;&#xFF0C;&#x4E3A;&#x6B64;&#x4F60;&#x9700;&#x8981;&#x914D;&#x7F6E;&#x53C2;&#x8003;&#x5B9E;&#x73B0;&#x7684;&#x73AF;&#x5883;&#x3002;
&#x73B0;&#x5728;&#x5DF2;&#x6709;&#x5982;&#x4E0B;&#x7684;&#x53C2;&#x8003;&#x5B9E;&#x73B0;&#xFF0C;&#x8BF7;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x559C;&#x597D;&#x9009;&#x62E9;&#x4E00;&#x4E2A;&#xFF0C;<code>git clone</code> &#x5230;&#x672C;&#x5730;&#xFF0C;&#x7136;&#x540E;&#x6309;&#x7167;&#x5B83;&#x7684; README &#x914D;&#x7F6E;&#x597D;&#x5B83;&#x7684;&#x73AF;&#x5883;&#x3002;</p>
<h3 id="python-antlr">Python-ANTLR</h3>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-dzy" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-dzy</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-dzy</code></li>
</ul>
<h3 id="rust-lalr1">Rust-lalr1</h3>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/mashplant" target="_blank">https://github.com/decaf-lang/minidecaf/tree/mashplant</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b mashplant</code></li>
</ul>
<h3 id="rust-manual">Rust-manual</h3>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-cy" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-cy</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-cy</code></li>
</ul>
<h3 id="java-antlr">Java-ANTLR</h3>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-xxy" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-xxy</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-xxy</code></li>
</ul>
<h3 id="c-antlr">C++-ANTLR</h3>
<p>&#x6709;&#x4E24;&#x4E2A;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#xFF1A;</p>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-tsz" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-tsz</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-tsz</code></li>
</ul>
<p>&#x7B2C;&#x4E8C;&#x4E2A;&#xFF1A;</p>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-zj" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-zj</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-zj</code></li>
</ul>
<h3 id="c-manual">C++-manual</h3>
<ul>
<li>&#x5730;&#x5740; <a href="https://github.com/decaf-lang/minidecaf/tree/md-zyr" target="_blank">https://github.com/decaf-lang/minidecaf/tree/md-zyr</a></li>
<li>clone &#x547D;&#x4EE4;&#xFF1A;<code>git clone git@github.com:decaf-lang/minidecaf.git -b md-zyr</code></li>
</ul>
<h1 id="&#x5907;&#x6CE8;">&#x5907;&#x6CE8;</h1>
<blockquote id="fn_1">
<sup>1</sup>. &#x5F00;&#x5934;&#x7684; <code>$</code> &#x8868;&#x793A;&#x63A5;&#x4E0B;&#x6765;&#x662F;&#x4E00;&#x6761;&#x547D;&#x4EE4;&#xFF0C;&#x8BB0;&#x5F97;&#x8FD0;&#x884C;&#x7684;&#x65F6;&#x5019;&#x53BB;&#x6389; <code>$</code>&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x8BA9;&#x4F60;&#x8FD0;&#x884C; <code>$ echo x</code>&#xFF0C;&#x90A3;&#x4F60;&#x6700;&#x7EC8;&#x6572;&#x5230;&#x7EC8;&#x7AEF;&#x91CC;&#x7684;&#x662F; <code>echo x</code>&#xFF08;&#x7136;&#x540E;&#x56DE;&#x8F66;&#xFF09;&#x3002;&#x5982;&#x679C;&#x5F00;&#x5934;&#x6CA1;&#x6709; <code>$</code>&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E00;&#x884C;&#x662F;&#x4E0A;&#x4E00;&#x6761;&#x547D;&#x4EE4;&#x7684;&#x8F93;&#x51FA;&#xFF08;&#x9664;&#x975E;&#x6211;&#x4EEC;&#x7279;&#x522B;&#x8BF4;&#x660E;&#xFF0C;&#x8FD9;&#x4E00;&#x884C;&#x662F;&#x4F60;&#x8981;&#x8F93;&#x5165;&#x7684;&#x5185;&#x5BB9;&#xFF09;&#x3002;<a href="#reffn_1" title="Jump back to footnote [1] in the text."> &#x21A9;</a>
</blockquote>
<blockquote id="fn_2">
<sup>2</sup>. Homebrew &#x4E5F;&#x63D0;&#x4F9B;&#x4E86; riscv-pk&#xFF0C;&#x4E0D;&#x8FC7;&#x90A3;&#x662F; 64 &#x4F4D;&#x7684;&#xFF0C;&#x800C;&#x6211;&#x4EEC;&#x9884;&#x7F16;&#x8BD1;&#x7684;&#x662F; 32 &#x4F4D;&#x7684;&#x3002;<a href="#reffn_2" title="Jump back to footnote [2] in the text."> &#x21A9;</a>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="testing.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 运行测试样例">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"环境配置","level":"2.1.1","depth":2,"next":{"title":"运行测试样例","level":"2.1.2","depth":2,"path":"docs/lab0/testing.md","ref":"docs/lab0/testing.md","articles":[]},"previous":{"title":"配环境、跑测试","level":"2.1","depth":1,"ref":"","articles":[{"title":"环境配置","level":"2.1.1","depth":2,"path":"docs/lab0/env.md","ref":"docs/lab0/env.md","articles":[]},{"title":"运行测试样例","level":"2.1.2","depth":2,"path":"docs/lab0/testing.md","ref":"docs/lab0/testing.md","articles":[]},{"title":"RISC-V 的工具链使用","level":"2.1.3","depth":2,"path":"docs/lab0/riscv.md","ref":"docs/lab0/riscv.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["hide-element","chapter-fold","katex","alerts","emphasize","mermaid-gb3","codeblock-label","code","search-pro","click-reveal","expandable-chapters-interactive","localized-footer"],"pluginsConfig":{"chapter-fold":{},"emphasize":{},"codeblock-label":{},"search-pro":{},"search":{},"localized-footer":{"filename":"gitalk.html","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":1},"click-reveal":{},"highlight":{},"mermaid-gb3":{},"expandable-chapters-interactive":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docs/lab0/env.md","mtime":"2020-09-02T07:27:37.403Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-08T05:38:47.833Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-click-reveal/click_reveal.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-interactive/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

